package com.small.nine.wxmp.domain.bean.wx.msg;

import com.small.nine.wxmp.common.constant.WxConstant;
import com.small.nine.wxmp.utils.wx.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 回复图片消息
 *
 * @author sheng_zs@126.com
 * @date 2021-08-02 17:30
 */
@Data
@EqualsAndHashCode(callSuper = true)
@XStreamAlias("xml")
public class WxImageMsgBean extends WxOutMsgBaseBean {
    private static final long serialVersionUID = 1L;

    /**
     * Image 节点
     */
    @XStreamAlias("Image")
    private ImageBean image;

    @Override
    public String toXml() {
        return XmlUtils.beanToXml(this);
    }

    /**
     * 初始化
     *
     * @param toUser     接收者，openID
     * @param fromUser   发送者
     * @param createTime 时间戳
     * @param mediaId    图片ID
     * @return {@link WxImageMsgBean}
     */
    public static WxImageMsgBean getInstance(String toUser, String fromUser, Long createTime, String mediaId) {
        WxImageMsgBean msgBean = new WxImageMsgBean();
        msgBean.setToUserName(toUser);
        msgBean.setFromUserName(fromUser);
        msgBean.setMsgType(WxConstant.MSG_TYPE_IMAGE);
        msgBean.setCreateTime(createTime);
        ImageBean bean = new ImageBean();
        bean.setMediaId(mediaId);
        msgBean.setImage(bean);
        return msgBean;
    }
}
